﻿<navigation:Page x:Class="SampleBrowser.Views.SampleSinglePage" 
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           xmlns:doc="http://schemas.firstfloorsoftware.com/documenttoolkit"
           xmlns:dte="http://schemas.firstfloorsoftware.com/documenttoolkit/extensions"
           xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Single Page Viewer">
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="136" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid.Resources>
            <dte:NullToVisibilityConverter x:Key="NullToVisibilityConverter" />
        </Grid.Resources>

        <TextBlock x:Name="HeaderText" Grid.ColumnSpan="2" Style="{StaticResource HeaderTextStyle}" Text="Single Page Viewer"/>

        <doc:DocumentDataSource x:Name="DataSource" LoadError="DataSource_LoadError" />

        <doc:ThumbnailListBox x:Name="Thumbnails" Grid.Row="1"
                              DocumentDataSource="{Binding ElementName=DataSource}"
                              PageIndex="{Binding PageIndex, Mode=TwoWay, ElementName=Navigator}" />

        <!-- document area -->
        <Grid x:Name="Panel" Grid.Column="1" Grid.Row="1">
            <ScrollViewer x:Name="ScrollViewer" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
                <Border x:Name="PageViewerBorder"
                        Background="White" BorderBrush="{StaticResource SliderTrackBrush}" BorderThickness="1" Margin="4" HorizontalAlignment="Center" VerticalAlignment="Center"
                        Visibility="{Binding Document, ElementName=DataSource, Converter={StaticResource NullToVisibilityConverter}}"
                        MouseLeftButtonDown="PageViewerBorder_MouseLeftButtonDown" MouseRightButtonUp="PageViewerBorder_MouseLeftButtonUp"
                        MouseMove="PageViewerBorder_MouseMove" LostMouseCapture="PageViewerBorder_LostMouseCapture" MouseWheel="PageViewerBorder_MouseWheel">
                    <doc:FixedPageViewer x:Name="PageViewer"
                                 FixedPage="{Binding FixedPage}" 
                                 FixedPageSize="{Binding FixedPageSize}"
                                 FixedPageError="{Binding FixedPageError}"
                                 Scale=".5">
                    </doc:FixedPageViewer>
                </Border>
            </ScrollViewer>
        </Grid>

        <StackPanel Grid.ColumnSpan="2" Grid.Row="2" Orientation="Horizontal" Margin="0,8,0,0" HorizontalAlignment="Center">
            <doc:PageNavigator x:Name="Navigator"
                               PageCount="{Binding Document.PageCount, ElementName=DataSource, FallbackValue=0}" Margin="4,0,0,0"
                               PageIndexChanged="Navigator_PageIndexChanged"/>

            <Button Margin="4,0,0,0" Padding="7">
                <Button.Command>
                    <dte:OpenPdfOrXpsFromDiskCommand DocumentDataSource="{Binding ElementName=DataSource}" />
                </Button.Command>
                <Button.Content>
                    <Image Source="/SampleBrowser;component/Assets/Icons/open.png" />
                </Button.Content>
            </Button>

        </StackPanel>
    </Grid>
</navigation:Page>
